. "$PSScriptRoot/common.ps1"
$apiKey = $env:NugetApiKey
$nugetUrl = "https://api.nuget.org/v3/index.json"
Set-Location $packFolder
$packages = Get-ChildItem -Path $packFolder -Filter *.nupkg -Recurse
$i = 0
$errorCount = 0
foreach ($package in $packages) {
    $i += 1
    $nugetPackageName = $package.FullName
    Write-Info "[$i / $($packages.Count)] - Pushing: $nugetPackageName"
    dotnet nuget push $nugetPackageName --skip-duplicate -s $nugetUrl --api-key "$apiKey"
    if (-Not $?) {
        Write-Error "推送失败: $nugetPackageName"
        $errorCount += 1
    }
    Write-Host "--------------------------------------------------------------`r`n"
}
if ($errorCount -gt 0) {
    Write-Host ("******* $errorCount error(s) occured *******") -ForegroundColor red
} 